using System;
using System.Collections.Generic;
using System.Text;
using TTDotNet.Engine.ThreeDEngine;
using TTDotNet.Engine.Vehicles;
using TTDotNet.Engine.Companies;
using TTDotNet.Engine.GUI.Windows;
using TTDotNet.Util;
using System.Drawing;

namespace TTDotNet.Engine.Create.Tools
{
    public class VehicleSelectTool : Tool
    {

        public VehicleSelectTool(Game game)
            : base(game, ToolType.VehicleSelect)
        {

        }

        public override void MouseDown(Point mouseLocation, GridPickData data)
        {
            ObjectInstance obj = Game.gameWorld.Scene.Pick(Game.myCamera, mouseLocation, ObjectType.Vehicle);
            
            if (obj.GUID != Guid.Empty)
            {
                if ((obj.Object as AJObject).ObjectType == TTDotNet.Util.ObjectType.Vehicle)
                {
                    Vehicle v = null;

                    foreach (Company company in Game.gameWorld.Companies.Values)
                    {
                        Fleet fleet = company.Fleet;

                        v = fleet.GetVehicle(obj.GUID);

                        if (v != null && v.IsInService)
                        {
                            OpenVehicleWindow(v);
                        }
                    }
                }
            }
        }

        private void OpenVehicleWindow(Vehicle v)
        {
            VehicleWindow vehicleWindow = new VehicleWindow(v, new System.Drawing.PointF(150, 150));
            Game.newGUI.OpenNewWindow(vehicleWindow);
        }
    }
}
